import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== $Lazy
const Page 		= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
const $time 	= $Lazy.file(()=>import('@com/utils/time'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// selectedKeys:[],
		// selectedRows:[],
		details:[],
		beforeDetails: [],
		// 搜索表单列表
		forms : [
			// { label: '标本条码',		name: 'spec_code' },
			// { label: '操作人',		name: 'operator_name'},
			// { label: '操作时间',		names: ['created_time_start_date','created_time_end_date'],	name:'jz-time',	type:'date-range', 	loading:true },
			// { label: '类型',		name: 'dtype', 		type:'select', 	loading:true,	render: text => {} },
			// { label: '描述',		name: 'title' },
			{ label: '标本条码',		name: 'SpecCode' },
			{ label: '操作人',		name: 'OperatorName'},
			{ label: '操作时间',		names: ['StartTime','EndTime'],	name:'jz-time',	type:'date-range', 	loading:true },
			{ label: '类型',		name: 'Dtype', 		type:'select', 	loading:true,	render: text => {} },
			{ label: '描述',		name: 'Title' },
		],
	}
	model = {}
	query = { _last:'' }
	
	componentDidMount(){
		this.getSelect()
		$time.then(f=>{
			const arr = f.duration['7-0-24']()
			this.resetModel = { StartTime: arr[0], EndTime: arr[1], 'jz-time':arr }
			this.model = $fn.copy(this.resetModel)
			if(window.isInit){
				this.fetch()
			}
		})
	}

	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 类型
			$fn.setRow( forms, 'Dtype', await f.getCache({ api:'slog/select' }) )
			// 
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'slog/index')
	// fetch = () => $fn.fetch.call(this,'http://logs.norsonmed.com:8008/querylogs')
	
	// 表单
	cols = [
		{ title: 'Id', 			dataIndex: 'id', 				...$fn.table.num },
		// { title: '模块', 		dataIndex: 'dtype_str', 		width:250 },
		{ title: '条码号', 		dataIndex: 'specCode', 		width: 100 },
		{ title: '操作人', 		dataIndex: 'operatorName', 	...$fn.table.name},
		{ title: '操作时间', 	dataIndex: 'createdTime',  	...$fn.table.time},	
		{ title: '描述', 		dataIndex: 'title', 			width:700 },
	]
	
	render(){
		// const { details, beforeDetails } = this.state
		return (
			<Page title='标本日志'>
				{/* 搜索 */}
				{ SearchForm.call(this, {timeStr:'7-0-24'}) }
				{/* 表格 */}
				{ Table.call(this, {isInit: window.isInit, noTotal: true, hasBottom: false, onSelectOk: ( keys,rows )=>{
					const row = rows[rows.length-1]
					if(row){
						const details = row.details
						const beforeDetails = row.before_details
						this.setState({ details, beforeDetails })
					}
				}}) }
				
				{/* 详细信息 */}
				{/*<div className='bor1 mt5' >
					<div>
						<div className='ptb5 tc b bbor1' style={{backgroundColor:'#f1fdfd'}} >详细信息</div>
						<div className='mtb10 plr10 oys scrollbar' style={{minHeight:20,maxHeight:60}} >{ details }</div>
					</div>*/}
					{/* 修改前信息 */}
					{/*<div>
						<div className='ptb5 tc b bbor1 tbor1' style={{backgroundColor:'#f1fdfd'}} >修改前信息</div>
						<div className='mtb10 plr10 oys scrollbar' style={{minHeight:20,maxHeight:60}} >{ beforeDetails }</div>
					</div>
				</div>*/}
			</Page>
		)
	}
}

export default Index